import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:speed_random/app_styles.dart';
import 'package:speed_random/common/common_fuc.dart';
import 'package:speed_random/global_data.dart';
import 'package:speed_random/pages/home/rand_com/com_results/logic.dart';
import 'package:speed_random/pages/home/rand_com/com_results/state.dart';
import 'package:share_plus/share_plus.dart';

class ItemResultsCom extends StatelessWidget {
  final ComResultsLogic logic;
  final ComResultsState state;
  final Map<String, dynamic> numbers;
  final Color textColor;
  final Color bgColor;
  final Function({String newShareText,String newcopyText}) onShareTextChanged; // 添加回调函数

  const ItemResultsCom({
    Key? key,
    required this.logic,
    required this.state,
    required this.numbers,
    this.textColor = AppStyles.colorPageText,
    this.bgColor = AppStyles.colorPagebg,
    required this.onShareTextChanged, // 必须传入回调函数
  }) : super(key: key);




  @override
  Widget build(BuildContext context) {
    var zonx = "总项".tr+"：${numbers["list"].split(",").length}";
    var sumx = "总和".tr+"：${numbers["sum"]}";
    var newShareText = numbers["list"];
    if(numbers["isshowsum"]){
      newShareText = newShareText+"\n"+zonx+"    "+sumx;
    }
    onShareTextChanged(newShareText: newShareText,newcopyText: newShareText);
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            numbers["list"].length>20?
            Expanded(child: Text(
              "${numbers["list"]}".tr,
              style:  TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: textColor,
              ),
            ))
                : Text(
              "${numbers["list"]}".tr,
              style:  TextStyle(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: textColor,
              ),
            ),
          ],
        ),
        const SizedBox(height: 10),
        if(numbers["isshowsum"])
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                zonx,
                style:  TextStyle(
                  fontSize: 14,
                  color: textColor,
                ),
              ),
              SizedBox(width: 10),
              Text(
                sumx,
                style:  TextStyle(
                  fontSize: 14,
                  color: textColor,
                ),
              ),
            ],
          )
      ],
    );
  }
}
